import 'package:fate_blind_box/widget/code_input_cursor.dart';
import 'package:flutter/material.dart';

/// 单个输入框item
class CodeInputItem extends StatelessWidget {
  const CodeInputItem(
      {super.key,
      required this.data,
      this.textStyle,
      this.decoration,
      required this.showCursor,
      this.cursorColor,
      required this.cursorWidth,
      required this.cursorIndent,
      required this.cursorEndIndent});

  final String data;
  final TextStyle? textStyle;
  final Decoration? decoration;

  ///
  /// 是否显示光标
  ///
  final bool showCursor;

  ///
  /// 光标颜色
  ///
  final Color? cursorColor;

  ///
  /// 光标宽度
  ///
  final double cursorWidth;

  ///
  /// 光标距离顶部距离
  ///
  final double cursorIndent;

  ///
  /// 光标距离底部距离
  ///
  final double cursorEndIndent;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        _buildInputBox(),
        showCursor
            ? Positioned.fill(
                child: CodeInputCursor(
                color: cursorColor ?? Theme.of(context).cardColor,
                width: cursorWidth,
                indent: cursorIndent,
                endIndent: cursorEndIndent,
              ))
            : Container()
      ],
    );
  }

  Widget _buildInputBox() {
    return Container(
      decoration: decoration,
      child: Center(
        child: Text(data, style: textStyle),
      ),
    );
  }
}
